//
//  ProtocolVC.m
//  doubleEduStudents
//
//  Created by 盛洋 on 2021/3/29.
//  Copyright © 2021 shengYang. All rights reserved.
//

#import "ProtocolVC.h"
#import "setCell.h"
#import "ProtocolInforVC.h"
#import "DeviceModel.h"


@interface ProtocolVC ()<UITableViewDelegate,UITableViewDataSource>
{
    GlobalTabel *table;
    NSArray *titleArr;
    RequestServices *service;
}

@end

@implementation ProtocolVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"隐私安全";
    [self.backKuang setHidden:YES];
    [self showBackCenterKuang:[UIImage imageNamed:@"back_center1"]];
    table = [[GlobalTabel alloc]init];
    [self.view addSubview:table];
    [table mas_makeConstraints:^(MASConstraintMaker *make) {
           make.width.equalTo(self.view).multipliedBy(0.8);
           make.height.equalTo(self.view).multipliedBy(0.7);
           make.centerX.equalTo(self.view.mas_centerX);
           make.centerY.equalTo(self.view.mas_centerY).offset(20);
       }];
    table.tableFooterView = [UIView new];
    table.separatorColor = table.backgroundColor =[UIColor clearColor];
    table.delegate = self;
    table.dataSource = self;
    [table registerNib:[UINib nibWithNibName:@"setCell" bundle:nil] forCellReuseIdentifier:@"setCell"];
    
    service.view = self.view;
    service = [[RequestServices alloc]initWithDelegate:self];
    [service getProtocolList:8000];
    
//    titleArr = [NSArray arrayWithObjects:@"隐私文件",@"用户服务协议",@"知识产权声明",@"反盗版声明",nil];
}

-(void)getFinished:(NSDictionary *)obj tag:(long long)tag{
    [self HideLoading];
    [self->table.mj_header endRefreshing ];
    [self->table.mj_footer endRefreshing];
    if (tag == 8000 ) {
        titleArr = [ProtocolModel mj_objectArrayWithKeyValuesArray:obj[@"list"]];
    }
    [self->table reloadData];
}

-(void)getError:(NSError *)error tag:(long long)tag{
    [self HideLoading];
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return titleArr.count;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
     return Is_iPhone ? 60 : 100;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    setCell *cell = [tableView dequeueReusableCellWithIdentifier:@"setCell" forIndexPath:indexPath];
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
//    cell.name_lab.text = titleArr[indexPath.section];
    cell.model = titleArr[indexPath.row];
    cell.content_lab.text = @"";
    [cell.icon_btn setImage:[UIImage imageNamed:@"mine_arrow"] forState:UIControlStateNormal];
    return cell;
}

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, table.frame.size.width, 20)];
    view.backgroundColor = [UIColor clearColor];
    return view;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 20;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    ProtocolInforVC *vc = [[ProtocolInforVC alloc]init];
    ProtocolModel *model = titleArr[indexPath.row];
    vc.url = model.url;
    [self PushToViewController:vc];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
